import { defineStore } from 'pinia';
import { login } from '@/api/common/system';
import cookie from '@/utils/cookie';

export const useLoginStore = defineStore('login', {
    state: ():LoginState => {
        return {
            username: '',
            password: '',
            autoLogin: false 
        }
    },

    actions: {
        updateLoginStore() {
            if(cookie.getCookie('LOGIN')) {
                const {username, password, autoLogin} = cookie.getCookie('LOGIN');
                this.username = username;
                this.password = password;
                this.autoLogin = autoLogin;
            }
        }
    }
})

interface LoginState {
    username: string;
    password: string;
    autoLogin: boolean
}